using System;
using System.Collections.Generic;
namespace Client.Hotfix
{
    public class HttpRequest
    {
        public string Url { get; set; }
        public string Api { get; private set; }
        public string Method { get; private set; }
        public Dictionary<string, string> Headers { get; set; }
        public object Body { get; private set; }
        public string ContentType { get; set; } = "application/json";
        public int Timeout { get; private set; } = 3;


        public HttpRequest()
        {
            var attribute = (WebApiAttribute)Attribute.GetCustomAttribute(GetType(), typeof(WebApiAttribute));
            if (attribute != null)
            {
                Api = attribute.Api;
            }
            else
            {
                this.Log($"{GetType().Name} APIAttribute is null!");
            }
        }

        public HttpRequest SetBody(object body)
        {
            Body = body;
            return this;
        }

        public HttpRequest SetMethod(string method)
        {
            Method = method;
            return this;
        }

        public HttpRequest AddHeader(string key, string value)
        {
            if (Headers == null)
            {
                Headers = new();
            }
            Headers[key] = value;
            return this;
        }

        public HttpRequest SetContentType(string contentType)
        {
            ContentType = contentType;
            return this;
        }

        public HttpRequest SetTimeout(int timeout)
        {
            Timeout = timeout;
            return this;
        }
    }

}
